﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Itop.YHPC.Model;
using Itop.YHPC.controller;
using System.Collections.Generic;

namespace Itop.YHPC.workflow
{
    public partial class workflow_check_ajax : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"];
            string id = Request.QueryString["id"];
            yhpcMain main = null;
            if (type == "check")
            {
                main = workflowController.GetMain(id);
                if (string.IsNullOrEmpty(main.dqyh) || DateTime.Now.Subtract(main.dqyhsj).Seconds > 30 || main.dqyh == (Session["user"] as sysuser).LoginID)//Session
                {
                    main.dqyh = (Session["user"] as sysuser).LoginID;
                    main.dqyhsj = DateTime.Now;
                    workflowController.Update(main);
                    Response.Write("0");
                }
                else
                    Response.Write("1");
            }
            else if (type == "update")
            {
                main = workflowController.GetMain(id);
                main.dqyh = (Session["user"] as sysuser).LoginID;
                main.dqyhsj = DateTime.Now;
                workflowController.Update(main);
            }
            else if (type == "gsbm")
            {
                Response.Write(GetGSBMByFL(Request.QueryString["fl"])+"|");
            }
        }

        public string GetGSBMByFL(string fl)
        {
            IList<yhpcDictionary> list = yhpcDictionaryController.GetList(" where type='专业分类' and text='" + fl + "'");
            if (list.Count > 0)
                return list[0].Remark;
            else
                return "";
        }
    }
}
